<?php

namespace Database\Factories\Rbac;

use App\Models\Rbac\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
 */
class UserFactory extends Factory
{
    /**
     * App\Models\Rbac\User::factory()->count(100)->create();
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */

    protected $model = User::class;

    public function definition()
    {
        $name = fake()->name;
        $name_pinyin = clearSpecialCharacter($name);
        $count = User::where('username',$name_pinyin)->count();
        if($count > 0){
            $names = $name_pinyin.str_pad($count+1,4,"0",STR_PAD_LEFT);
        }else{
            $names = $name_pinyin;
        }
        $first_user = User::find(1);
        return [
            'username'=>$names,
            'password'=>123456,
            'company_name'=>$name,
            'phone'=>fake()->phoneNumber,
            'is_primary'=>2,
            'parent_username' => $first_user->username,
        ];
    }




}
